import React, { Component } from "react";

class Child extends Component {
  // 父子组件的render和componentDidMount的执行顺序
  // 父render -> 子render -> 子componentDidMount -> 父componentDidMount

  // 父组件只要render了，子组件一定也会render
  render() {
    console.log("child render");
    return <div>child组件 - {this.props.count}</div>;
  }
  componentDidMount() {
    console.log("child componentDidMount");
  }

  //! props的更新阶段
  // 被销毁了
  // 组件的props更新的时候会触发
  UNSAFE_componentWillReceiveProps() {
    console.log("child componentWillReceiveProps");
  }

  shouldComponentUpdate(nextProps) {
    console.log("child shouldComponentUpdate");
    return nextProps.count !== this.props.count;
  }
}

export default Child;
